package com.sky.controller.admin;


import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Slf4j
@Api("订单管理接口")
public class OrdersContoller {


    @Autowired
    OrdersService ordersService;
    /**
     * 分页查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult page = ordersService.page(ordersPageQueryDTO);

        return Result.success(page);
    }


    /**
     * 确认订单
     * @param ordersConfirmDTO
     * @return
     */
    //TODO 响应没反应报404看答案
    @PutMapping("/comfirm")
    @ApiOperation("确认订单")
    public Result comfirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒绝订单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result<Orders> orderDetails(@PathVariable Long id){
        Orders orders = ordersService.OrderDetails(id);
        return Result.success(orders);
    }

    /**
     * 分页查询待接订单
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询待接订单")
    @GetMapping("/statistics")
    public Result<PageResult> pageStatus2(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult page = ordersService.page(ordersPageQueryDTO);

        return Result.success(page);
    }

}
